package com.fagertveit.android.game.cb;

import com.fagertveit.android.game.framework.geom.Circle;
import com.fagertveit.android.game.framework.geom.Vector2;

public class Ball {
	private Vector2 oldPos;
	private Vector2 pos;
	private Vector2 dir;
	private float vel;
	private float speed;
	private Circle shape;
	private float size;
	
	public Ball() {
		pos = new Vector2(256, 256);
		dir = new Vector2(-0.8f, 0.8f);
		shape = new Circle(256, 256, 8);
		speed = 100;
		size = 8;
	}
	
	public void setPos(Vector2 pos) {
		this.pos = pos;
	}
	
	public Vector2 getPos() {
		return pos;
	}
	
	public Vector2 getDrawPos() {
		return new Vector2(this.pos.x - this.size, this.pos.y - this.size);
	}
	
	public void setDir(Vector2 dir) {
		this.dir = dir;
	}
	
	public Vector2 getDir() {
		return dir;
	}
	
	public void updateShape() {
		shape.setPos(pos.x, pos.y);
	}
	
	public Circle getShape() {
		return shape;
	}
	
	public void stepBack() {
		pos = oldPos.copy();
		updateShape();
	}
	
	public boolean update(float delta) {
		vel += speed * delta;
		if(vel > 1.0f) {
			dir.scale(vel);
			oldPos = pos.copy();
			pos = pos.add(dir);
			updateShape();
			dir = dir.nor();
			vel = 0.0f;
			return true;
		} else {
			return false;
		}
	}
}
